package com.rem.se.reflect;

import lombok.Data;

/**
 * Class的无参构造方式都有哪些
 *
 * @author Rem
 * @date 2021-03-14
 */

public class Demo02 {


    public static void main(String[] args) throws ClassNotFoundException {
        Person student = new Student();
        System.out.println("这是:" + student.getName());

        //通过对象获得
        Class c1 = student.getClass();

        //通过forName获得
        Class<?> c2 = Class.forName("com.rem.se.reflect.Student");

        //通过类名.class获得
        Class c3 = Student.class;

        //基本内置类型的包装类可以获得
        Class c4 = Integer.TYPE;

        //获得父类的Class
        Class c5 = c1.getSuperclass();

        System.out.println(c1);
        System.out.println(c2);
        System.out.println(c3);
        System.out.println(c4);
        System.out.println(c5);
    }
}

@Data
class Person {

    private String name;


    public Person() {
        System.out.println("Person 无参构造");
    }
}


class Student extends Person {

    public Student() {
        this.setName("学生");
        System.out.println("Student 无参构造");
    }
}


class Teacher extends Person {

    public Teacher() {
        this.setName("老师");
        System.out.println("Teacher 无参构造");
    }
}